package com.gupaoedu.vip.register;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description: 单例模式之注册式
 * 优点：线程安全
 * @Author: fuyl
 * @since 2019年03月14日
 * @Version: 1.0
 */
public class Register {

    private Register(){}

    /** 线程安全 */
    private static Map<String,Object> map = new ConcurrentHashMap<>();

    public static Object getObject(String className){
        if(!map.containsKey(className)){
            Object obj = null;
            try{
                obj = Class.forName(className);
                map.put(className,obj);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            return obj;
        }else{
            return map.get(className);
        }
    }
}
